//
//  KWTMGRNSettingSyncCell.m
//  RuiHeApp
//
//  Created by Yan Chen on 2024/7/29.
//

#import "KWTMGRNSettingSyncCell.h"
@interface KWTMGRNSettingSyncCell()

@property(nonatomic,strong)QMUILabel *deviceNameLab;

@property(nonatomic,strong)QMUILabel *deviceTypeLab;

@property(nonatomic,strong)QMUILabel *statusLab;

@property(nonatomic,strong)UIImageView *deviceIcon;

@end
@implementation KWTMGRNSettingSyncCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}
-(void)setDeviceModel:(RHDeviceModel *)deviceModel
{
    _deviceModel = deviceModel;
    self.deviceNameLab.text = deviceModel.deviceName;
    self.deviceTypeLab.text = [NSString stringWithFormat:@"%@-%@",ValidNullData(deviceModel.productTypeName),ValidNullData(deviceModel.deviceTypeName)];
    self.selectIcon.image = [UIImage imageNamed:deviceModel.isSelected?@"ugrade_select":@"ugrade_cancel"];
    //在线
    if([deviceModel.status isEqualToString:@"0"]){
        self.deviceIcon.image = [UIImage imageNamed:@"kwt_distribute_dev_online"];
        self.statusLab.text = @"在线".rh_localized;
        self.statusLab.textColor = CMainColorGreen;
    }else if([deviceModel.status isEqualToString:@"1"]){
        //离线
        self.deviceIcon.image = [UIImage imageNamed:@"kwt_distribute_dev_offline"];
        self.statusLab.text = @"离线".rh_localized;
        self.statusLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
    }
}
- (void)setupUI{
    
    [self setBackgroundColor:UIColor.clearColor];
    [self.contentView setBackgroundColor:UIColor.clearColor];
    
    UIView *containView = [[UIView alloc]init];
    [self.contentView addSubview:containView];
    containView.backgroundColor = [UIColor whiteColor];
    containView.layer.cornerRadius = 8;
    containView.layer.masksToBounds = YES;
    
    _selectIcon = [[UIImageView alloc]init];
    _selectIcon.contentMode = UIViewContentModeScaleAspectFit;
    [_selectIcon setImage:[UIImage imageNamed:@"device_disSelected"]];
    [containView addSubview:_selectIcon];
    
    
    _deviceNameLab = [[QMUILabel alloc]init];
    [containView addSubview:_deviceNameLab];
    _deviceNameLab.font = [UIFont boldSystemFontOfSize:15];
    _deviceNameLab.text = @"User";
    _deviceNameLab.textAlignment = NSTextAlignmentLeft;
    _deviceNameLab.textColor = [UIColor colorWithHexString:@"3F4443"];

    
    _deviceTypeLab = [[QMUILabel alloc]init];
    [containView addSubview:_deviceTypeLab];
    _deviceTypeLab.font = [UIFont boldSystemFontOfSize:13];
    _deviceTypeLab.text = @"5";
    _deviceTypeLab.textAlignment = NSTextAlignmentLeft;
    _deviceTypeLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
   
    
    
    kWeakSelf;
    _deviceIcon = [[UIImageView alloc]init];
    _deviceIcon.contentMode = UIViewContentModeScaleAspectFit;
    [containView addSubview:_deviceIcon];
    [_deviceIcon setImage:[UIImage imageNamed:@"device_icon"]];
    
//    _statusLab = [[QMUILabel alloc]init];
//    [containView addSubview:_statusLab];
//    _statusLab.font = [UIFont boldSystemFontOfSize:12];
//    _statusLab.text = @"--";
//    _statusLab.textAlignment = NSTextAlignmentLeft;
//    _statusLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
  
    [containView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsMake(10, 10, 10, 10));
    }];
    
    
    
    [_deviceIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.width.height.offset(kScaleW(30));
        make.centerY.mas_offset(0);
            
    }];
    
    [_deviceNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.deviceIcon.mas_right).offset(10);
            make.right.equalTo(weakSelf.selectIcon.mas_left).offset(-10);
            make.top.mas_offset(15);
//            make.height.offset(25);
    }];
    
    [_deviceTypeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.deviceNameLab);
            make.top.equalTo(weakSelf.deviceNameLab.mas_bottom).offset(5);
            make.bottom.mas_offset(-15);
    }];
    
    [_selectIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(18);
        make.right.mas_offset(-15);
        make.centerY.mas_offset(0);
    }];
    
//    [_statusLab mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.mas_offset(-5);
//        make.centerX.equalTo(weakSelf.deviceIcon);
//    }];
}

@end
